import React, { useState } from "react";

const A = ({ onGetAMsg }) => {
  const aname = "这是A组件的组件";
  return (
    <div>
      <h2>A组件</h2>
      <button onClick={() => onGetAMsg(aname)}>发送</button>
    </div>
  );
};

const B = ({ value }) => {
  return (
    <div>
      <h2>B组件-- {value}</h2>
    </div>
  );
};

const App = () => {
  const [value, setValue] = useState("");
  const getAMsg = (msg) => {
    console.log(msg);
    setValue(msg);
  };

  return (
    <div>
      <h2>父组件</h2>
      <A onGetAMsg={getAMsg}></A>
      <B value={value}></B>
    </div>
  );
};

export default App;
